//---------------------------------------------------------------------------
/** 雑用関数
 */
//---------------------------------------------------------------------------
/*
 * Copyright (c) 1999 - 2005 shimitei
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "misc.h"
//---------------------------------------------------------------------------
/** ファイル名のディレクトリ部分を返す
 * ルートでも最後に"\\"が付かないようにする
 * ExtractFileDir, ExtractFilePath などはルートが特別扱いになるため
 * @param path フルパス
 * @return
 */
AnsiString __fastcall ExtractDirName(const AnsiString &path)
{
    AnsiString retstr ;

    retstr = ExtractFileDir( path ) ;
    if ( retstr.Length() <= 3 )
    {
        retstr = retstr.SetLength( 2 ) ;
    }

    return retstr ;
}
//---------------------------------------------------------------------------
/** ファイルの存在をチェック
 * @param path フルパス
 * @return 
#define NO_EXISTS 0 存在しない
#define IS_FILE   1 ファイル
#define IS_DIR    2 フォルダ
*/
int __fastcall ExistsCheck(const AnsiString &path)
{
    WIN32_FIND_DATA ffd ;
    HANDLE hf ;
    int ret = NO_EXISTS ;

    if ( path.Length() <= 3 )
    {
        // フルパスを期待しているので３文字以下はルート
        ret = IS_DIR ; // ただしディレクトリ扱い
    }

    hf = FindFirstFile( path.c_str(), &ffd ) ;
    if ( hf != INVALID_HANDLE_VALUE )
    {
        if ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
        {
            ret = IS_DIR ;
        } else {
            ret = IS_FILE ;
        }
    }
    FindClose( hf ) ;

    return ret ;
}
//---------------------------------------------------------------------------
/** MessageBox()のラップ
 * @param Text 表示する文字列
 * @param Flags MB_OK以外に追加するフラグ
 */
void __fastcall Message(const AnsiString &Text, int Flags)
{
    //Application->NormalizeTopMosts() ;
    Application->MessageBox( Text.c_str(), Application->Title.c_str(), MB_OK | Flags ) ;
    //Application->RestoreTopMosts() ;
}
//---------------------------------------------------------------------------

